<?php
	class Prodect_model extends CI_Model {
		public $table_name="prodect";
    public function get_one($id)
    {
        $prodect=$this->db->where('id',$id)->get($this->table_name);
          return $prodect->row();
    }
    public function get_all()
    {	
        $articles = $this->db->limit(4)->where('recommend',1)->order_by('id',"desc")->get($this->table_name);
        return $articles->result();
    }
     public function get_by_catalog_id($catalog_id)
    {
        $prodect=$this->db->where(array('catalog_id'=>$catalog_id,'recommend'=>0))->limit(6)->get($this->table_name);
        return $prodect->result();
    }
     public function get_by_recommend($catalog_id)
     {
         $prodect=$this->db->where(array('catalog_id'=>$catalog_id,'recommend'=>1))->limit(1)->get($this->table_name);
          return $prodect->row();
     }
      public function get_by_catalogs_id($where,$brand_id)  
    {   
        $w=array();
        if($brand_id!=false){
            $w['brand_id']=$brand_id;
        }
        $prodect=$this->db->where_in("catalog_id",$where)->where($w)->get($this->table_name);
        return $prodect->result();
    }
        public function get_brand_by_catalogs_id($catalog_id)
    {   
        $catalog=$this->Prodect_catalog_model->get_one_pc($catalog_id);
        $child_catalog=$this->Prodect_catalog_model->get_child_pc($catalog_id);
        $where=array($catalog->id);
        foreach ($child_catalog as $c) {
            $where[]=$c->id;
    }
        $query=$this->db->select('brand_id')->where_in('catalog_id',$where)->distinct()->get($this->table_name);
        $brands=$query->result();
        $brand_ids=array();
        foreach ($brands as $b) {
            $brand_ids[]=$b->brand_id;
        }
        $query=$this->db->where_in("id",$brand_ids)->get("prodect_brand");
        return $query->result();
    }
}
    
